Improve push failure error message for API key package ID scope mismatch#10775
Improve push failure error message for API key package ID scope mismatch#10775
Conversation
|
Azure Pipelines: 1 pipeline(s) require an authorized user to comment /azp run to run. |
1 similar comment
|
Azure Pipelines: 1 pipeline(s) require an authorized user to comment /azp run to run. |
|
|
||
| string message; | ||
| if (result.PermissionsCheckResult == PermissionsCheckResult.Allowed && !result.IsOwnerConfirmed) | ||
| if (!result.ScopesAreValid) |
There was a problem hiding this comment.
Is this message appropriate for all cases when ScopesAreValid is false?
There was a problem hiding this comment.
No — ScopesAreValid is false whenever matchingScope == null, which covers both a package-ID mismatch and an action mismatch (e.g., a PackageUnlist-scoped key used to push). In the action-mismatch case the package-ID message would be misleading.
Fixed in d54d492 by adding an IsPackageIdScopeMismatch property to ApiScopeEvaluationResult. It's set to true only when at least one scope already allows the requested action — meaning the subject (package ID) is specifically what failed. The controller now checks result.IsPackageIdScopeMismatch instead of !result.ScopesAreValid, so the specific message is shown only for genuine package-ID scope mismatches and the generic message is shown for action mismatches.
There was a problem hiding this comment.
With help of copilot, looking at the code, I can see two cases:
- Package ID scope mismatch: the API key's Scope.Subject pattern doesn't match the package ID.
- Action scope mismatch: the API key's Scope.AllowedAction doesn't include the requested action (e.g., the key only allows "unlist" but the user is trying to "push").
Maybe the message should be
"The specified API key does not have permission to perform this action on this package. The API key may have a package ID scope that does not include this package ID, or it may not allow the requested action."
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
d54d492 to
b2952a9
Compare
Agent-Logs-Url: https://github.com/NuGet/NuGetGallery/sessions/aa085293-31cc-41ec-b433-e820261dd577 Co-authored-by: chabiss <[email protected]>
b2952a9 to
36ae755
Compare
Broaden the message to cover action mismatches in addition to package ID scope mismatches. Co-authored-by: Copilot <[email protected]>
When an API key's package ID scope doesn't match the package being pushed, users receive the same generic 403 as invalid/expired keys — making the root cause impossible to self-diagnose.
ApiKeyNotAuthorized_PackageIdScopeMismatchstring resource with a descriptive message about the package ID scopeIsPackageIdScopeMismatchproperty toApiScopeEvaluationResult, set totrueonly when at least one scope allows the requested action but no scope's subject pattern matches the package ID — ensuring the specific message is shown only for genuine package-ID scope mismatches, not action mismatchesIsPackageIdScopeMismatchinApiScopeEvaluator.Evaluateby checking whether any scope allows the requested action regardless of subject; guards againstnullrequestedActionsGetHttpResultFromFailedApiScopeEvaluationHelper, checkresult.IsPackageIdScopeMismatch(instead of the broader!result.ScopesAreValid) to return the specific message only when the package ID is the failing dimensionInvalidScopes_Datatest fixture to cover bothisPackageIdScopeMismatch: true(specific message) andisPackageIdScopeMismatch: false(generic message) casesSetsIsPackageIdScopeMismatchWhenSubjectDoesNotMatchButActionDoestest toApiScopeEvaluatorFacts^4.17.21→^4.18.0(resolves to 4.18.1); runnpm audit fixto remove nested vulnerable lodash 4.17.23 instances inglobule/grunt-legacy-*transitive deps (GHSA-r5fr-rjxr-66jc)